using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayAudioComp : MonoBehaviour
{
    private AudioSource[] attackAudioChild;

    private AudioSource[] moveAudioSources;
    private AudioSource hitAudioSource;
    private bool isPlay;
    private AudioSource jumpAudioSource;
    private AudioSource[] stateAudioSources;

    public AudioSource AddHealthAudioSource;

    // Start is called before the first frame update
    void Awake()
    {
        Transform AttackAudioChild = transform.Find("Attack Audio Source");
        attackAudioChild = AttackAudioChild.GetComponents<AudioSource>();

        Transform moveAudioChild = transform.Find("Move Audio Source");
        moveAudioSources = moveAudioChild.GetComponents<AudioSource>();

        Transform hitAudioChild = transform.Find("Hit Audio Source");

        hitAudioSource = hitAudioChild.GetComponent<AudioSource>();
        Transform AddHealthAudioChild = transform.Find("AddHealthVFX");
        if (AddHealthAudioChild)
            AddHealthAudioSource = AddHealthAudioChild.GetComponent<AudioSource>();

        Transform stateAudioChild = transform.Find("State Audio Source");
        if (stateAudioChild)
            stateAudioSources = stateAudioChild.GetComponents<AudioSource>();

        Transform jumpAudio = transform.Find("Jump Audio Source");
        if (jumpAudio)
            jumpAudioSource = jumpAudio.GetComponent<AudioSource>();

    }

    public void PlayMoveAudio()
    {
        int randomIndex = Random.Range(0, 10);
        moveAudioSources[randomIndex].Play();
    }
    public void PlayHitAudio()
    {
        hitAudioSource.Play();
    }

    public void PlayAttackAudio()
    {
        int randomIndex = Random.Range(0, 3);
        attackAudioChild[randomIndex].Play();
    }

    public void PlayTouchEnemyHitAudio()
    {
        hitAudioSource.Play();
    }
    public void PlayJumpAudio()
    {
        jumpAudioSource.Play();
    }

    internal void Lose()
    {
        stateAudioSources[0].Play();
    }
    internal void Win()
    {
        stateAudioSources[1].Play();
    }
    public void PlayAddHealthAudio()
    {
        AddHealthAudioSource.Play();
    }
}
